home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Mark Pilgrim / Brailler 0.5ß / Brailler 0.5ß.source / brlr ƒ / brlr floating window.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-30  |  4.4 KB  |  208 lines  |  [TEXT/MMCC]

  1. #include "brlr floating window.h"
  2. #include "brlr grade 2 meat.h"
  3. #include "environment.h"
  4. #include "main.h"
  5. #include "menus.h"
  6. #include "util.h"
  7. #include "graphics.h"
  8. #include "window layer.h"
  9. #include "program globals.h"
  10.  
  11. enum { key_LeftArrow=0x1c, key_RightArrow, key_UpArrow, key_DownArrow };
  12. enum { key_PageUp=0x0b, key_PageDown };
  13. enum { key_Home=0x01 };
  14. enum { key_End=0x04 };
  15.  
  16. #define HEADER_SPACE        (30+TE_HEIGHT)
  17. #define FOOTER_SPACE        5
  18. #define DEAD_SPACE_LEFT        6
  19. #define DEAD_SPACE_RIGHT    DEAD_SPACE_LEFT
  20. #define WINDOW_WIDTH        200
  21. #define    WINDOW_HEIGHT        75
  22. #define TE_HEIGHT            12
  23.  
  24. static    CursHandle        gMyIBeamHandle;
  25. static    Boolean            gFloaterIsActive;
  26. static    Point            lastTopLeft;
  27. static    Boolean            gSetupDone=FALSE;
  28.  
  29. void SetupTheFloatingWindow(WindowPtr theWindow)
  30. {
  31.     unsigned char    *titleStr="\pGrade 2";
  32.     Point            topLeft;
  33.     
  34.     SetWindowHeight(theWindow, WINDOW_HEIGHT);
  35.     SetWindowWidth(theWindow, WINDOW_WIDTH);
  36.     SetWindowType(theWindow, 2064);
  37.     SetWindowHasCloseBox(theWindow, FALSE);
  38.     SetWindowMaxDepth(theWindow, 1);
  39.     SetWindowDepth(theWindow, 1);
  40.     SetWindowIsFloat(theWindow, TRUE);
  41.     SetWindowTitle(theWindow, titleStr);
  42.     SetWindowAutoCenter(theWindow, FALSE);
  43.     
  44.     if (gSetupDone)
  45.     {
  46.         topLeft=lastTopLeft;
  47.     }
  48.     else
  49.     {
  50.         topLeft.v=qd.screenBits.bounds.bottom-150;
  51.         topLeft.h=(qd.screenBits.bounds.left+qd.screenBits.bounds.right)/2+
  52.             qd.screenBits.bounds.left-(WINDOW_WIDTH/2);
  53.     }
  54.     SetWindowTopLeft(theWindow, topLeft);
  55.     
  56.     if (gSetupDone)
  57.         return;
  58.     
  59.     gMyIBeamHandle=GetCursor(iBeamCursor);
  60. }
  61.  
  62. void ShutDownTheFloatingWindow(void)
  63. {
  64.     ReleaseResource((Handle)gMyIBeamHandle);
  65. }
  66.  
  67. void OpenTheFloatingWindow(WindowPtr theWindow)
  68. {
  69.     TEHandle        hTE;
  70.     FontInfo        theFontInfo;
  71.     Rect            destRect, viewRect;
  72.     
  73.     hTE=GetWindowTE(theWindow);
  74.     if (hTE==0L)
  75.     {
  76.         SetRect(&destRect, 10, 10, WINDOW_WIDTH-10, 10+TE_HEIGHT);
  77.         viewRect=destRect;
  78.         hTE=TENew(&destRect, &viewRect);
  79.         SetWindowTE(theWindow, hTE);
  80.         TextFont((**hTE).txFont=monaco);
  81.         TextSize((**hTE).txSize=9);
  82.         TextFace((**hTE).txFace=0);
  83.         TextFont(0);
  84.         TextSize(12);
  85.         TextFace(0);
  86.         GetFontInfo(&theFontInfo);
  87.         (**hTE).fontAscent=theFontInfo.ascent;
  88.         (**hTE).lineHeight=theFontInfo.ascent+theFontInfo.descent+theFontInfo.leading;
  89.         TEAutoView(TRUE, hTE);
  90.     }
  91.     
  92.     gFloaterIsActive=TRUE;
  93.     AdjustMenus();
  94. }
  95.  
  96. void CloseTheFloatingWindow(WindowPtr theWindow)
  97. {
  98.     lastTopLeft=GetWindowTopLeft(theWindow);
  99. }
  100.  
  101. void IdleInFloatingWindow(WindowPtr theWindow, Point mouseLoc)
  102. {
  103.     TEHandle        hTE;
  104.     
  105.     if (gInProgress)
  106.         return;
  107.     
  108.     hTE=GetWindowTE(theWindow);
  109.     TEIdle(hTE);
  110.     if (PtInRect(mouseLoc, &((**hTE).viewRect)))
  111.     {
  112.         if (!gCustomCursor)
  113.         {
  114.             SetCursor(*gMyIBeamHandle);
  115.             gCustomCursor=TRUE;
  116.         }
  117.     }
  118.     else
  119.     {
  120.         gCustomCursor=FALSE;
  121.     }
  122. }
  123.  
  124. void KeyPressedInFloatingWindow(WindowPtr theWindow, unsigned char theChar)
  125. {
  126.     TEHandle        hTE;
  127.     
  128.     if (gInProgress)
  129.         return;
  130.     
  131.     hTE=GetWindowTE(theWindow);
  132.     TEKey(theChar, hTE);
  133.     switch (theChar)
  134.     {
  135.         case ' ':
  136.         case '\r':
  137.         case 0x03:
  138.             if (GetFrontDocumentWindow()!=GetIndWindowPtr(kMainWindow))
  139.                 MySelectWindow(GetIndWindowPtr(kMainWindow));
  140.             DealWithGrade2Word(hTE);
  141.             TESetSelect(0, 32767, hTE);
  142.             TEDelete(hTE);
  143.             break;
  144.     }
  145.     TESelView(hTE);
  146. }
  147.  
  148. void MouseClickedInFloatingWindow(WindowPtr theWindow, Point thePoint)
  149. {
  150.     Boolean            gotone;
  151.     TEHandle        hTE;
  152.     
  153.     if (gInProgress)
  154.         return;
  155.     
  156.     gotone=FALSE;
  157.     hTE=GetWindowTE(theWindow);
  158.     if (PtInRect(thePoint, &((**hTE).destRect)))
  159.         TEClick(thePoint, (GetTheModifiers()&512) ? TRUE : FALSE, hTE);
  160. }
  161.  
  162. void DisposeTheFloatingWindow(WindowPtr theWindow)
  163. {
  164.     TEHandle        hTE;
  165.     
  166.     hTE=GetWindowTE(theWindow);
  167.     if (hTE!=0L)
  168.     {
  169.         TEDispose(hTE);
  170.         SetWindowTE(theWindow, 0L);
  171.     }
  172. }
  173.  
  174. void ActivateTheFloatingWindow(WindowPtr theWindow)
  175. {
  176.     TEActivate(GetWindowTE(theWindow));
  177.     gFloaterIsActive=TRUE;
  178. }
  179.  
  180. void DeactivateTheFloatingWindow(WindowPtr theWindow)
  181. {
  182.     TEDeactivate(GetWindowTE(theWindow));
  183.     gFloaterIsActive=FALSE;
  184.     gCustomCursor=FALSE;
  185. }
  186.  
  187. void DrawTheFloatingWindow(WindowPtr theWindow, short theDepth)
  188. {
  189.     GrafPtr            curPort;
  190.     Rect            tempRect;
  191.     
  192.     GetPort(&curPort);
  193.     EraseRect(&(curPort->portRect));
  194.     tempRect=(**GetWindowTE(theWindow)).viewRect;
  195.     InsetRect(&tempRect, -4, -4);
  196.     FrameRect(&tempRect);
  197.     
  198.     MoveTo(DEAD_SPACE_LEFT, HEADER_SPACE);
  199.     TextFont(geneva);
  200.     TextSize(9);
  201.     TextFace(0);
  202.     DrawString("\pText will be converted to grade 2 Braille");
  203.     MoveTo(DEAD_SPACE_LEFT, HEADER_SPACE+12);
  204.     DrawString("\pand inserted as soon as you type SPACE,");
  205.     MoveTo(DEAD_SPACE_LEFT, HEADER_SPACE+24);
  206.     DrawString("\pRETURN, or ENTER.");
  207. }
  208.